package com.xywy.tangandroid.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.activity.DoctorChurchFrameAct;
import com.xywy.tangandroid.activity.FreeAskQuestionAct;
import com.xywy.tangandroid.vollery.VolleyManager;

public class DoctorFragement extends Fragment implements OnClickListener {
	
	private RelativeLayout left_img;
	private TextView middle_title;
	private TextView right_title;
	private LinearLayout tobar;
	private ImageView right_img;
	private RelativeLayout free_doctor_ask_relat;
	private RelativeLayout phone_doctor_relat;
	private RelativeLayout famous_doctor_relat;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragement_doctor_online, null);
		initView(view);
		initonclick();
		return view;

	}

	private void initView(View view) {

		left_img = (RelativeLayout)view. findViewById(R.id.left_img);
		middle_title = (TextView)view. findViewById(R.id.middle_title);
		right_title = (TextView) view.findViewById(R.id.right_title);
		right_img = (ImageView)view. findViewById(R.id.right_img);
		left_img.setVisibility(View.INVISIBLE);
		middle_title.setText(getResources().getString(R.string.doctor_online));

		free_doctor_ask_relat = (RelativeLayout) view.findViewById(R.id.free_doctor_ask_relat);
		phone_doctor_relat = (RelativeLayout) view.findViewById(R.id.phone_doctor_relat);
		famous_doctor_relat = (RelativeLayout) view.findViewById(R.id.famous_doctor_relat);
	}

	private void initonclick() {
		free_doctor_ask_relat.setOnClickListener(this);
		phone_doctor_relat.setOnClickListener(this);
		famous_doctor_relat.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.free_doctor_ask_relat:
               Intent intent=new Intent(getActivity(), FreeAskQuestionAct.class);
               intent.putExtra("mark", 100);
               startActivity(intent);
			break;
		case R.id.phone_doctor_relat:
//			Intent intent1=new Intent(getActivity(), FreeAskQuestionAct.class);
//			intent1.putExtra("mark", 200);
//            startActivity(intent1);
			 createDialog() ;
			
			break;
		case R.id.famous_doctor_relat:
			
			Intent intent2=new Intent(getActivity(), DoctorChurchFrameAct.class);
            startActivity(intent2);
			break;

		default:
			break;
		}
	}
	@Override
	public void onResume() {
		super.onResume();
	}
	
	
	 @Override
     public void onDestroy() {
	super.onDestroy();
	 VolleyManager.cancelRequest(getActivity());
    }
	 /**
	  * 打电话的对话框
	  */
	 private void createDialog() {
			Dialog dialog = new AlertDialog.Builder(getActivity())
					.setTitle("温馨提示")
					.setMessage("您是否要拨打寻医问药的健康电话:400-9700-1200")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://400-9700-1200"));    
				            startActivity(intent); 
							
						}
					})
					.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						}
					}).create();
			// 显示提示框
			dialog.show();
		}
}
